package month1;

public class SwapNodesInPairs24_04 {
    public static void main(String[] args) {
        System.out.println(swapPairs(new ListNode(new int[]{1, 2, 3, 4, 5})));
    }

    /**
     * 递归
     *
     * @param head
     * @return
     */
    static ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode node = head.next;
        head.next = swapPairs(head.next.next);
        node.next = head;
        return node;
    }
}
